import { ref } from "vue";
import { showToast } from "@/utils/toastHelper";
import { useLocalStorage } from "@vueuse/core";
import { useRouter } from "vue-router";

export function useMemoList() {
  const list = useLocalStorage("memo-list", []);
  const loading = ref(false);
  const router = useRouter();
  const finished = ref(true);

  function deleteMemo(id) {
    list.value = list.value.filter((i) => i.id !== id);
    showToast("删除成功");
  }

  function editMemo(id) {
    router.push(`/memo/${id}`);
  }

  return {
    list,
    loading,
    finished,
    deleteMemo,
    editMemo,
  }
}
